import 'package:flutter/services.dart';

/// * 作者: Tao
/// * 日期: 2024/3/22
/// * 时间: 16:16
/// * 描述: 自定义兼容中文拼音输入法正则校验输入框
class CustomizedTextFormatter extends TextInputFormatter {
  final Pattern filterPattern;

  CustomizedTextFormatter({required this.filterPattern});

  @override
  TextEditingValue formatEditUpdate(
    TextEditingValue oldValue,
    TextEditingValue newValue,
  ) {
    if (newValue.isComposingRangeValid) return newValue;
    return FilteringTextInputFormatter.allow(filterPattern)
        .formatEditUpdate(oldValue, newValue);
  }
}
